//
// Created by black on 2024/7/12.
//

#include "interruptible_thread.h"



void interrupt_flag::set() {
    flag.store(true, std::memory_order_relaxed);
    std::lock_guard<std::mutex> l(set_clear_mutex);
    if(thread_cond) {
        thread_cond->notify_all();
    }
    else if(thread_cond_any) {
        thread_cond_any->notify_all();
    }
}

bool interrupt_flag::is_set() const {
    return flag.load(std::memory_order_relaxed);
}

void interrupt_flag::interruption_point() {
    if(is_set()) {
        throw thread_interrupted();
        flag.store(false, std::memory_order_relaxed);
    }
}
